package com.codefish.codefish_blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codefish.codefish_blog.entity.CommentLikeRecord;
import com.codefish.codefish_blog.mapper.ArticleLikeRecordMapper;
import com.codefish.codefish_blog.mapper.CommentLikeRecordMapper;
import com.codefish.codefish_blog.service.CommentLikeRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author codefish
 * @since 2022-03-26
 */
@Service
public class CommentLikeRecordServiceImpl extends ServiceImpl<CommentLikeRecordMapper, CommentLikeRecord> implements CommentLikeRecordService {
    @Autowired
    CommentLikeRecordMapper commentLikeRecordMapper;

    @Override
    public Set<Long> searchLikesOnComments(Long articleId, Integer userId) {
        List<Long> res = commentLikeRecordMapper.searchLikesOnComments(articleId, userId);
        return new HashSet<>(res);
    }


    @Override
    public void addLikeRecord(Long commentId, Integer likerId) {
        CommentLikeRecord record = new CommentLikeRecord();
        record.setPid(commentId);
        record.setLikerId(likerId);
        this.save(record);
    }

    @Override
    public void removeLikeRecord(Long commentId, Integer likerId) {
        QueryWrapper<CommentLikeRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("pid", commentId)
                .eq("liker_id", likerId);
        this.remove(wrapper);
    }
}
